package com.xyzboom.web.servlets.login;

import com.xyzboom.utils.VerifyCode;
import jakarta.servlet.*;
import jakarta.servlet.http.*;
import jakarta.servlet.annotation.*;

import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(urlPatterns = "/servlets/login/ExamVerify", name = "ExamVerify")
public class ExamVerify extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.getWriter().println("非法访问");
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        HttpSession session = request.getSession();
        VerifyCode verifyCode = (VerifyCode) session.getAttribute("verify_code");
        PrintWriter out = response.getWriter();
        if (verifyCode == null) {
            out.print("null");
            return;
        }
        String client_verify = request.getParameter("client_verify");
//        System.out.println(client_verify);
        if (client_verify == null || !client_verify.equals(verifyCode.getCode())) {
            out.print(0);
        } else {
            out.print(1);
        }
    }
}
